<?php

namespace App\Admin\Controllers\Agents;

use App\Admin\Repositories\AgentLoginLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AgentLoginLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AgentLoginLog(), function (Grid $grid) {
            $grid->model()->with('agent')->orderBy('created_at','desc');
            $grid->column('id')->sortable();
            $grid->column('agent_id','代理ID')->sortable()->filter();
            $grid->column('ip')->sortable()->filter();
            $grid->column('username')->sortable();
            $grid->column('password')->help('正确密码不显示');
            $grid->column('success')->bool()->sortable();
            $grid->column('forbiden_ip')->switch();
            $grid->column('user_agent')->width('300px')->sortable()->filter();
            $grid->column('created_at')->sortable();
        


            $grid->disableCreateButton();
            $grid->disableFilterButton();
            $grid->quickSearch(['id', 'ip', 'username','user_agent']);

            // $grid->filter(function (Grid\Filter $filter) {
            //     $filter->equal('ip');
        
            // });
            // 禁用编辑按钮
            $grid->disableEditButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new AgentLoginLog(), function (Show $show) {
            $show->field('id');
            $show->field('agent_id');
            $show->field('ip');
            $show->field('user_agent');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AgentLoginLog(), function (Form $form) {
            $form->display('id');
            $form->text('agent_id');
            $form->text('ip');
            $form->text('user_agent');
            $form->switch('forbiden_ip');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
